package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanProjectVo;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划模块")
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     * @return
     */
    @GetMapping
    @ApiOperation("查询所有护理计划")
    private ResponseResult<List<NursingPlanVo>> GetAllNursingPlan(){
        List<NursingPlanVo> nursingPlanVos =  nursingPlanService.GetAllNursingPlan();
        return success(nursingPlanVos);
    };



    /**
     * 分页查询护理计划
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/search")
    private  ResponseResult<PageResponse<NursingPlanVo>> GetPageNursingPlan(
            @ApiParam("名称")  String name,
            @ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam("显示条数") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @ApiParam("状态") Integer status
    ){
        PageResponse<NursingPlanVo> nursingPlanVoPageResponse =  nursingPlanService.getPage(name,pageNum,pageSize,status);
        return success(nursingPlanVoPageResponse);
    }

    /**
     * 新增护理计划
     * @param nursingPlanDto
     * @return
     */
    @PutMapping
    @ApiOperation("新增护理计划")
   private ResponseResult addNursingPlan(@RequestBody @ApiParam("新增护理计划数据") NursingPlanDto nursingPlanDto){
        nursingPlanService.addNursingPlan(nursingPlanDto); // 调用service层的新增护理计划方法
        return success();//返回对应结果
    }

    /**
     * 根据id查询护理计划
     * @param id
     * @return
     */
    @ApiOperation("根据id查询护理计划")
    @GetMapping("/{id}")
   private ResponseResult<NursingPlanVo> getById(@ApiParam("查询护理计划id") @PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getByid(id);
        return success(nursingPlanVo);
    }

    /**
     * 修改护理计划
     * @param nursingPlanDto
     * @param id
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation("修改护理计划")
    private ResponseResult updatePlan(@ApiParam(value = "修改护理计划数据",required = true ) @RequestBody NursingPlanDto nursingPlanDto,
                                      @ApiParam(value = "护理计划id",required = true) @PathVariable Long id ){
        nursingPlanService.updatePlan(nursingPlanDto);
        return success();
    }

    /**
     * 根据id删除护理计划
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理计划")
    private ResponseResult deletePlan(@PathVariable @ApiParam(value = "护理项目计划id" ,required = true) Long id){
        nursingPlanService.deleteByid(id);
        return success();
    }

    /**
     * 启用或禁用护理计划
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理等级状态")
    private ResponseResult enableOrTurn(
            @PathVariable @ApiParam(value = "护理计划id",required = true) Long id,
            @PathVariable @ApiParam(value = "护理计划状态",required = true) Integer status){
        nursingPlanService.updatestatus(id,status);
        return success();
    }



}
